﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using ClubManager.Models;
using ClubManager.Models.Location;
using ClubManager.Models.People;

namespace ClubManager.DAL
{
    public class ClubDbInitializer : DropCreateDatabaseIfModelChanges<ClubDb>
    {
        protected override void Seed(ClubDb context)
        {
            var states = new List<State>
                             {
                                 new State {Id=15,Name="Hawaii",Code="HI"},
                                 new State {Id=13,Name="Georgia",Code="GA"},
                                 new State {Id=12,Name="Florida",Code="FL"},
                                 new State {Id=11,Name="District of Columbia",Code="DC"},
                                 new State {Id=10,Name="Delaware",Code="DE"},
                                 new State {Id=09,Name="Connecticut",Code="CT"},
                                 new State {Id=08,Name="Colorado",Code="CO"},
                                 new State {Id=06,Name="California",Code="CA"},
                                 new State {Id=05,Name="Arkansas",Code="AR"},
                                 new State {Id=04,Name="Arizona",Code="AZ"},
                                 new State {Id=02,Name="Alaska",Code="AK"},
                                 new State {Id=01,Name="Alabama",Code="AL"},
                                new State { Name="Idaho",Code="ID", Id=16},
                                new State { Name="Illinois",Code="IL", Id=17},
                                new State { Name="Indiana",Code="IN", Id=18},
                                new State { Name="Iowa",Code="IA", Id=19},
                                new State { Name="Kansas",Code="KS", Id=20},
                                new State { Name="Kentucky",Code="KY", Id=21},
                                new State { Name="Louisiana",Code="LA", Id=22},
                                new State { Name="Maine",Code="ME", Id=23},
                                new State { Name="Maryland",Code="MD", Id=24},
                                new State { Name="Massachusetts",Code="MA", Id=25},
                                new State { Name="Michigan",Code="MI", Id=26},
                                new State { Name="Minnesota",Code="MN", Id=27},
                                new State { Name="Mississippi",Code="MS", Id=28},
                                new State { Name="Missouri",Code="MO", Id=29},
                                new State { Name="Montana",Code="MT", Id=30},
                                new State { Name="Nebraska",Code="NE", Id=31},
                                new State { Name="Nevada",Code="NV", Id=32},
                                new State { Name="New Hampshire",Code="NH", Id=33},
                                new State { Name="New Jersey",Code="NJ", Id=34},
                                new State { Name="New Mexico",Code="NM", Id=35},
                                new State { Name="New York",Code="NY", Id=36},
                                new State { Name="North Carolina",Code="NC", Id=37},
                                new State { Name="North Dakota",Code="ND", Id=38},
                                new State { Name="Ohio",Code="OH", Id=39},
                                new State { Name="Oklahoma",Code="OK", Id=40},
                                new State { Name="Oregon",Code="OR", Id=41},
                                new State { Name="Pennsylvania",Code="PA", Id=42},
                                new State { Name="Rhode Island",Code="RI", Id=44},
                                new State { Name="South Carolina",Code="SC", Id=45},
                                new State { Name="South Dakota",Code="SD", Id=46},
                                new State { Name="Tennessee",Code="TN", Id=47},
                                new State { Name="Texas",Code="TX", Id=48},
                                new State { Name="Utah",Code="UT", Id=49},
                                new State { Name="Vermont",Code="VT", Id=50},
                                new State { Name="Virginia",Code="VA", Id=51},
                                new State { Name="Washington",Code="WA", Id=53},
                                new State { Name="West Virginia",Code="WV", Id=54},
                                new State { Name="Wisconsin",Code="WI", Id=55},
                                new State { Name="Wyoming",Code="WY", Id=56}                             
                                                             };
            foreach (var state in states)
            {
                context.States.Add(state);
            }
            context.SaveChanges();

            var clubs = new List<Club>
                            {
                                new Club
                                    {
                                        Name = "Ajax FC",
                                        WelcomeMessage = "Welcome to Ajax FC Web Site!",
                                        Address = new Address
                                                      {
                                                          Name = "Main Field Address",
                                                          Street = "325 Maple St",
                                                          City = "Naperville",
                                                          State = states.Find(state=>state.Code=="IL"),
                                                          PostalCode = "60490"
                                                      }
                                    }
                            };
            foreach (var club in clubs)
            {
                context.Clubs.Add(club);
            }
            context.SaveChanges();

            var defaultSeason = new Season{Id=1,Starts = DateTime.Now,Ends = DateTime.Now+TimeSpan.FromDays(60),Name="Winter 2011/2012",
            Teams = new HashSet<ClubTeam>
                        {
                            new ClubTeam
                            {
                                AgeGroup = AgeGroup.U10,
                                Gender = Gender.Male,
                                Players = new HashSet<Player>
                                          {
                                              new Player {FirstName = "Mickey",LastName = "Mouse"},
                                              new Player {FirstName = "Bob",LastName = "Sponge"},
                                              new Player {FirstName = "Bugs",LastName = "Bunny"},
                                              new Player {FirstName = "Tom",LastName = "Cat"},
                                              new Player {FirstName = "Jerry",LastName = "Mouse"},
                                              new Player {FirstName = "Woody",LastName = "Woodpecker"},
                                              new Player {FirstName = "Donald",LastName = "Duck"},
                                              new Player {FirstName = "Yogi",LastName = "Bear"},
                                          }},
                            new ClubTeam
                                {
                                    AgeGroup = AgeGroup.U12,Gender = Gender.Male
                                }
                        }};
            context.Seasons.Add(defaultSeason);
            context.SaveChanges();

        }
    }
}